package JavaSE;

class OperationResults{
    //定义成员变量
    int sum;//和
    int difference;//差
    int product;//积
    int quotient;//商
    int remainer;//余数

    //类的构造方法，用于初始化成员变量
    public OperationResults(int sum,int difference,int product,int quotient,int remainer){
        this.sum = sum;
        this.difference = difference;
        this.product = product;
        this.quotient = quotient;
        this.remainer = remainer;
    }
}

public class 运算符练习之使用类同时返回多个值ArithmeticOperations1{
    public static OperationResults performOperations(int x,int y){
        int sum = x+y;
        int difference = x-y;
        int product = x*y;
        int quotient = y!=0?x/y:0;//以防被除数为0
        int remainer = y!=0?x%y:0;//以防被除数为0
        return new OperationResults(sum,difference,product,quotient,remainer);//直接返回一个对象，把算好的值传回给对象，然后在main方法中直接打印返回对象里存的和、差、积、商、余数即可
    }
    public static void main(String[] args){

        int a = 10;
        int b = 5;
        OperationResults results = performOperations(a,b);

        //用对象点出对象里的成员变量的值，然后打印输出
        System.out.println("和:"+results.sum);
        System.out.println("差:"+results.difference);
        System.out.println("积:"+results.product);
        System.out.println("商:"+results.quotient);
        System.out.println("余数:"+results.remainer);
    }
}